package com.company.gas.controller;

import com.company.gas.pojo.Staff;
import com.company.gas.service.IStaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
/**
 * @author: Li Guangdi
 *
 */
@RestController
@RequestMapping("/gas/staff")
@Api(tags = "员工管理相关接口")
public class StaffController {

    @Autowired
    private IStaffService iStaffService;

    //查询全部员工
    @GetMapping("/queryStaffList")
    @ApiOperation("查询全部员工")
    public List<Staff> queryStaffList(){
        List<Staff> staffList = iStaffService.queryStaffList();
        return staffList;
    }
    //根据staffId查询指定员工
    @GetMapping("/queryStaffById")
    @ApiOperation("根据staffId查询指定员工")
    public Staff queryStaffById(@RequestParam(value = "员工ID") String staffId) {
        Staff staff = iStaffService.queryStaffById(staffId);
        System.out.println(staff);
        return staff;
    }

    //添加一个员工
    @GetMapping("/addStaff")
    @ApiOperation("添加一个员工")
    public String addStaff(@RequestParam(value = "员工ID") String staffId,@RequestParam(value = "员工姓名") String staffName,
                        @RequestParam(value = "部门") String department,@RequestParam(value = "职位") String position,
                           @RequestParam(value = "员工电话") String staffPhone,
                        @RequestParam(value = "薪水") BigDecimal salary,@RequestParam(value = "标识符") Integer flag,
                        @RequestParam(value = "创建者") String createBy,@RequestParam(value = "修改者") String modifyBy) {
        int isAddStaff = iStaffService.addStaff(staffId,staffName, department,position,staffPhone,salary,flag,createBy,modifyBy);
        if(isAddStaff == 1){
            return "add success";
        }else {
            return "add fail";
        }
    }

    //修改员工信息
    @GetMapping("/updateStaff")
    @ApiOperation("修改员工信息")
    public String updateStaff(@RequestParam(value = "员工ID") String staffId, @RequestParam(value = "员工姓名") String staffName,
                              @RequestParam(value = "部门") String department,@RequestParam(value = "部门") String position,
                              @RequestParam(value = "电话") String staffPhone,
                              @RequestParam(value = "薪水") BigDecimal salary, @RequestParam(value = "标识符") Integer flag,
                              @RequestParam(value = "修改者") String modifyBy){
        int isUpdateStaff = iStaffService.updateStaff(staffId,staffName,department,position,staffPhone,salary,flag,modifyBy);
        if(isUpdateStaff == 1){
            return "update success";
        }else {
            return "update fail";
        }
    }

    //根据staffId删除指定员工
    @GetMapping("/deleteStaff")
    @ApiOperation("根据staffId删除指定员工")
    public String deleteStaff(@RequestParam(value = "员工ID") String staffId){
        int isDeleteStaff = iStaffService.deleteStaff(staffId);
        if(isDeleteStaff == 1){
            return "delete success";
        }else {
            return "delete fail";
        }
    }


}
